package com;

import com.softkey.jsyunew3;

public class SoftKey {

    private jsyunew3 j9;

    public SoftKey() {
        j9 = new jsyunew3();
    }

    public jsyunew3 getj9() {
        return j9;
    }

    public String getID(String in, String ou) {
        System.out.println(j9.GetID_1(in));
        System.out.println(j9.GetID_2(ou));
        String st = "";
        String append = "";
//        st = Integer.toHexString((int) j9.GetID_1(in)).toUpperCase();
//        st = String.format("%5s",st);
//        append += st.replaceAll(" ","0");
//        st = Integer.toHexString((int) j9.GetID_2(ou)).toUpperCase();
//        st = String.format("%5s",st);
//        append += st.replaceAll(" ","0");
        return append;
    }

    //使用增强算法，加密字符串
    public String StrEnc(String InString, String Key) {

        byte[] b, outb;
        byte[] temp_b = InString.getBytes();
        byte[] temp = new byte[8], outtemp = new byte[8];
        int n, i, nlen, outlen;
        String outString;

        nlen = temp_b.length;
        nlen = nlen + 1;
        if (nlen < 8)
            outlen = 8;
        else
            outlen = nlen;
        b = new byte[outlen];
        outb = new byte[outlen];

        for (n = 0; n < nlen - 1; n++) {
            b[n] = temp_b[n];
        }

        outb = b.clone();

        for (n = 0; n <= outlen - 8; n = n + 8) {
            for (i = 0; i < 8; i++) temp[i] = b[i + n];
            EnCode(temp, outtemp, Key);
            for (i = 0; i < 8; i++) outb[i + n] = outtemp[i];
        }

        outString = "";
        for (n = 0; n <= outlen - 1; n++) {
            outString = outString + myhex(outb[n]);
        }
        return outString;
    }

    //使用增强算法，解密字符串
    public String StrDec(String InString, String Key) {

        byte[] b, outb;
        byte[] temp = new byte[8], outtemp = new byte[8];
        int n, i, nlen, outlen;
        String outString, temp_String;


        nlen = InString.length();
        if (nlen < 16) outlen = 16;
        outlen = nlen / 2;
        b = new byte[outlen];
        outb = new byte[outlen];

        i = 0;
        for (n = 1; n <= nlen; n = n + 2) {
            temp_String = InString.substring(n - 1, n - 1 + 2);
            b[i] = (byte) HexToInt(temp_String);
            i = i + 1;
        }

        outb = b.clone();

        for (n = 0; n <= outlen - 8; n = n + 8) {
            for (i = 0; i < 8; i++) temp[i] = b[i + n];
            DeCode(temp, outtemp, Key);
            for (i = 0; i < 8; i++) outb[i + n] = outtemp[i];
        }

        outString = new String(outb);
        outString = outString.trim();
        return outString;
    }

    public void EnCode(byte[] inb, byte[] outb, String Key) {

        long cnDelta, y, z, a, b, c, d, temp_2;
        long[] buf = new long[16];
        int n, i, nlen;
        long sum;
        long temp, temp_1;
        long mask = 4294967295L;

        //UInt32 temp, temp_1;
        String temp_String;


        cnDelta = 2654435769L;
        sum = 0;

        nlen = Key.length();
        i = 0;
        for (n = 1; n <= nlen; n = n + 2) {
            temp_String = Key.substring(n - 1, n - 1 + 2);
            buf[i] = HexToInt(temp_String);
            i = i + 1;
        }
        a = 0;
        b = 0;
        c = 0;
        d = 0;
        for (n = 0; n <= 3; n++) {
            a = (buf[n] << (n * 8)) | a;
            b = (buf[n + 4] << (n * 8)) | b;
            c = (buf[n + 4 + 4] << (n * 8)) | c;
            d = (buf[n + 4 + 4 + 4] << (n * 8)) | d;
        }


        y = 0;
        z = 0;
        for (n = 0; n <= 3; n++) {
            temp_2 = conver(inb[n]);
            y = (temp_2 << (n * 8)) | y;
            temp_2 = conver(inb[n + 4]);
            z = (temp_2 << (n * 8)) | z;
        }


        n = 32;

        while (n > 0) {
            sum = (cnDelta + sum) & mask;

            temp = (z << 4) & mask;
            temp = (temp + a) & mask;
            temp_1 = (z + sum) & mask;
            temp = (temp ^ temp_1) & mask;
            temp_1 = (z >> 5) & mask;
            temp_1 = (temp_1 + b) & mask;
            temp = (temp ^ temp_1) & mask;
            temp = (temp + y) & mask;
            y = temp & mask;
            /*y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); */

            temp = (y << 4) & mask;
            temp = (temp + c) & mask;
            temp_1 = (y + sum) & mask;
            temp = (temp ^ temp_1) & mask;
            temp_1 = (y >> 5) & mask;
            temp_1 = (temp_1 + d) & mask;
            temp = (temp ^ temp_1) & mask;
            temp = (z + temp) & mask;
            z = temp & mask;
            /* z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d); */
            n = n - 1;

        }
        for (n = 0; n <= 3; n++) {
            outb[n] = (byte) ((y >>> (n * 8)) & 255);
            outb[n + 4] = (byte) ((z >>> (n * 8)) & 255);
        }
    }

    public void DeCode(byte[] inb, byte[] outb, String Key) {

        long cnDelta, y, z, a, b, c, d, temp_2;
        long[] buf = new long[16];
        int n, i, nlen;
        long sum;
        long temp, temp_1;

        long mask = 4294967295L;

        //UInt32 temp, temp_1;
        String temp_String;


        cnDelta = 2654435769L;
        sum = 3337565984L;

        nlen = Key.length();
        i = 0;
        for (n = 1; n <= nlen; n = n + 2) {
            temp_String = Key.substring(n - 1, n - 1 + 2);
            buf[i] = HexToInt(temp_String);
            i = i + 1;
        }
        a = 0;
        b = 0;
        c = 0;
        d = 0;
        for (n = 0; n <= 3; n++) {
            a = (buf[n] << (n * 8)) | a;
            b = (buf[n + 4] << (n * 8)) | b;
            c = (buf[n + 4 + 4] << (n * 8)) | c;
            d = (buf[n + 4 + 4 + 4] << (n * 8)) | d;
        }


        y = 0;
        z = 0;
        for (n = 0; n <= 3; n++) {
            temp_2 = conver(inb[n]);
            y = (temp_2 << (n * 8)) | y;
            temp_2 = conver(inb[n + 4]);
            z = (temp_2 << (n * 8)) | z;
        }


        n = 32;

        while (n > 0) {


            temp = (y << 4) & mask;
            temp = (temp + c) & mask;
            temp_1 = (y + sum) & mask;
            temp = (temp ^ temp_1) & mask;
            temp_1 = (y >> 5) & mask;
            temp_1 = (temp_1 + d) & mask;
            temp = (temp ^ temp_1) & mask;
            temp = (z - temp) & mask;
            z = temp & mask;
            /* z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d); */

            temp = (z << 4) & mask;
            temp = (temp + a) & mask;
            temp_1 = (z + sum) & mask;
            temp = (temp ^ temp_1) & mask;
            temp_1 = (z >> 5) & mask;
            temp_1 = (temp_1 + b) & mask;
            temp = (temp ^ temp_1) & mask;
            temp = (y - temp) & mask;
            y = temp & mask;
            /*y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); */

            sum = (sum - cnDelta) & mask;
            n = n - 1;

        }
        for (n = 0; n <= 3; n++) {
            outb[n] = (byte) ((y >>> (n * 8)) & 255);
            outb[n + 4] = (byte) ((z >>> (n * 8)) & 255);
        }
    }

    public long get_LastError() {
        return j9.get_LastError();
    }

    public String FindPort(int start) {
        return j9.FindPort(start);
    }

    //使用带长度的方法从指定的地址读取字符串
    private String ReadStringEx(int addr, String DevicePath) {
        int nlen, ret;
        byte[] buf = new byte[1];
        //先从地址0读到以前写入的字符串的长度
        ret = j9.YReadEx((short) addr, (short) 1, "DFF77660", "776C8777", DevicePath);
        System.out.println("字符串的长度"+ret);
        if (ret != 0) return "";
        nlen = j9.GetBuf(0);
        System.out.println(nlen);
        //再读取相应长度的字符串
        return j9.NewReadString(addr + 1, nlen, "DFF77660", "776C8777", DevicePath);
    }

    //使用从储存器读取相应数据的方式检查是否存在指定的加密锁
    public int CheckKeyByReadEprom() {
        int n, ret;
        String DevicePath = "";//用于储存加密锁所在的路径
        String outString = "";
        //@NoUseCode_data return 1;//如果没有使用这个功能，直接返回1
        for (n = 0; n < 255; n++) {
            DevicePath = j9.FindPort(n);
            if (j9.get_LastError() != 0) return (int) j9.get_LastError();
            outString = ReadStringEx(2, DevicePath);
            if ((j9.get_LastError() == 0) && (outString.compareTo("CF33801B9D3A8BA972D0ABB8C4F02AEE") == 0)) return 0;
        }
        return -92;
    }

    //使用增强算法一检查加密锁，
    public int CheckKeyByEncstring() {
        int n, ret;
        String DevicePath = "";//用于储存加密锁所在的路径
        String outString = "";
        int myrnd = (int) (Math.random() * 500);
        String[] EncInString = {"19314", "27651", "382", "4997", "15886", "5272", "9866", "26633", "5512", "12049", "5221", "1697", "8523", "30002", "9673", "18204", "8671", "19805", "12176", "4847", "8943", "15508", "10932", "26410", "30021", "30840", "32335", "30335", "18636", "6476",
                "27035", "27458", "26253", "27633", "3572", "18787", "2739", "25578", "6353", "28788", "24197", "11609", "3533", "15785", "4721", "24319", "12449", "19922", "6142", "19519", "3882", "24417", "31703", "30490", "11103", "21609", "24519", "8756", "17755", "21660",
                "5303", "717", "17753", "3916", "21681", "4808", "17841", "7530", "7391", "678", "15583", "905", "10123", "19337", "18300", "21465", "1567", "24884", "4674", "28719", "23333", "1034", "25611", "27644", "13384", "13066", "18385", "3665", "1105", "15832",
                "22191", "29664", "15657", "30390", "8670", "20733", "2524", "1158", "15543", "21400", "10387", "21704", "26294", "9540", "25752", "11681", "21876", "3378", "12373", "24529", "7851", "12853", "24404", "6332", "16949", "31934", "65", "21601", "21516", "6369",
                "22242", "28516", "17995", "6222", "30243", "22791", "21290", "13399", "31247", "25899", "1797", "12271", "25039", "15956", "27220", "22951", "2478", "30625", "19380", "11699", "17684", "16087", "10716", "6115", "6284", "11862", "15783", "21929", "5057", "16160",
                "9231", "30744", "19323", "23256", "10287", "1506", "29605", "3521", "11583", "15704", "6475", "22713", "14491", "30317", "31891", "9031", "7100", "9395", "2763", "19849", "15931", "31067", "30809", "25155", "2005", "9528", "31435", "26839", "27232", "15036",
                "8905", "22343", "3034", "12280", "22044", "9269", "4187", "159", "27056", "30945", "1052", "28673", "23438", "816", "25976", "27411", "11488", "26529", "20202", "2663", "23536", "21337", "16651", "13356", "32296", "11801", "3222", "24117", "31250", "27713",
                "23650", "28662", "24921", "215", "24428", "17535", "27333", "28536", "4814", "19587", "3139", "32362", "11201", "20563", "13529", "2190", "8607", "20962", "9908", "28516", "22497", "3778", "28957", "11538", "26659", "8741", "2687", "1622", "3102", "18139",
                "2658", "23699", "10156", "14681", "882", "8142", "29383", "14767", "32118", "24740", "17290", "11664", "3933", "604", "30765", "25165", "6445", "3284", "269", "28377", "7697", "7824", "2720", "13766", "15955", "32433", "18307", "1861", "20829", "20219",
                "23151", "25384", "8121", "24014", "24638", "23267", "15634", "6189", "6635", "4999", "561", "7097", "13966", "26564", "9983", "26804", "15714", "10735", "31879", "13314", "6082", "1528", "18165", "22819", "15143", "882", "14224", "27705", "29482", "10126",
                "1732", "27656", "19336", "14110", "11801", "5104", "6680", "6294", "16954", "19955", "10453", "22022", "27889", "17589", "32729", "16161", "1834", "5494", "20319", "11064", "21227", "8728", "31167", "23358", "21857", "798", "15734", "31684", "20693", "6570",
                "32538", "18174", "24241", "16765", "13161", "18108", "10624", "8954", "26937", "13936", "18154", "9507", "29576", "1326", "12731", "32664", "13165", "30629", "25563", "27806", "548", "27177", "4183", "31509", "15110", "12973", "32085", "129", "25996", "8897",
                "32290", "11010", "32594", "10647", "3368", "13146", "26129", "5634", "1520", "12012", "24995", "30834", "32546", "442", "19971", "9469", "17548", "28772", "25929", "21842", "28950", "21039", "10673", "27331", "10442", "25340", "28563", "20547", "29393", "13644",
                "1900", "31843", "13176", "17474", "2003", "4951", "17958", "9631", "14210", "10479", "14183", "23494", "5974", "8862", "7907", "18361", "3142", "14709", "6502", "15129", "10605", "7207", "25304", "10793", "6662", "12549", "4165", "32202", "11113", "30721",
                "27094", "1408", "30482", "3248", "25813", "2410", "11418", "18496", "15788", "31820", "31674", "901", "12774", "19848", "7759", "30960", "23083", "23327", "593", "18068", "9287", "949", "5081", "4131", "27938", "22665", "10019", "16622", "15048", "28544",
                "647", "28136", "5731", "21786", "2177", "22435", "1595", "7802", "426", "3153", "10171", "7009", "1724", "10690", "26989", "10290", "2705", "16235", "25851", "8175", "1060", "20572", "22832", "28217", "14477", "30023", "17397", "16723", "9479", "7808",
                "7252", "23582", "2285", "30198", "11383", "2078", "4024", "24894", "2984", "10098", "6914", "9097", "14417", "26334", "11397", "8104", "20988", "4037", "28698", "14861"};
        String[] EncOutString = {"92BB66CDBA6C447C", "A382733C6F721B25", "11FD5CF3FC9D629C", "0F8A520647C7B75E", "987D8E0EB0185241", "BF9FF0F9776B62A5", "E2C2F6A30BC4ECCE", "E2CC7CA0E1C759BC", "456828C5F84141C0", "178B459B6AADFD5C", "BF59B4AE5FD74CDC", "6360B6DA3709B562", "CE18F6A1A638739E", "3F2252409216BDE7", "98719549F1631493", "14409ECBB6D9A0A3", "F67E0CE522C727F3", "B46D7F5C84207F10", "BE80E354F4720933", "B0C8C7CE84757849", "DEBC5F1364B59F6A", "16575DD2111A4158", "8AD9EC944B5250D3", "64BD2A0A08ABC4FA", "2991A3AA44E55EFE", "8F590837B67EEA0D", "2D75CD384A0CB54B", "99CF6BD39BD17B2D", "D8903AE2260DE135", "46A4026B62E6FA86",
                "8399AA83A6543F71", "4F4F832E2AF40814", "4A5F348014E623B3", "20B9DCC8C3D20B5F", "9172CE455DCB9EE5", "AF59D9DDB0088DE4", "EB3CA538E0065666", "606694C2EA1E3FC8", "1CACC4BBA12C33EC", "DF95F14FF1AA29D9", "432484D63B8ED742", "03FC797A873C11E7", "B902074C61A6B55A", "B95F29EA27FFD52E", "91CA86E92A68F092", "6374D20F23F80DCE", "CC97CC5D2267B63D", "906674D7E4778B3D", "6DBC239925DB08EE", "B5453C87FDE69E0B", "08488E04A54FAB98", "023D9253AEC9D06B", "B16D8B2746E87480", "49CB335F34506BBD", "B2F3C69F4A03C471", "A17BEF620A406A23", "27AAE50711BA886C", "B3347142D2800E72", "0B30D5705345E398", "45662FCF00931D6B",
                "94B1A97AE35B967C", "96BE772DB527DC59", "D698F59D73FBF5EE", "AC1F2224262DE653", "7005742856246FD2", "9FDA8FD120528456", "33FE87FFE7D439E2", "2EF37D11DAB7A5CD", "A9A32ED6EB752E8B", "A7BF33834258821C", "2FAFEBE2FC98C13B", "A5B0269F576D8AB2", "8190BCD63A958888", "A0034497DA6F0E6D", "71D4C560C339EC7E", "934DB379CE4EAC3A", "466417BD475C65A1", "734FF2D1E0EA7578", "F527B413F5D5095A", "95A12808EC4B1DE0", "56A3911676363558", "CD5D284C605BC865", "5D7232D926441C9C", "A5B57430522E5704", "F3E6B5EA80990263", "313CFFE502C1FCE9", "B64579E73EAFF3D9", "30E5EB23A41DC37A", "5E84835E4089DE18", "17E54F5AD012946D",
                "97E93A84E3361750", "488FCAD6BF52FA1A", "56D93416FAD291DC", "CA69BAF0407521E0", "29511B414FEC8F2E", "2CCADD9708FED661", "5361B1C3EB26E5CF", "B797F764098DDEBC", "35C2E9EE53BB6435", "BE80CBB492136699", "44B089A3E9DFFF0F", "3D9A410FD94E9178", "E26600F116891606", "75439C90C5121433", "EB3A5C771DAD3005", "A4FB2F50EF1CBED1", "4B23DB9D4F25D840", "012EFAECAFC43B58", "4BD8054A68A5B7E4", "034DB2383B8B37C2", "DF78D44010CE9D2B", "76C21D9AA758CC57", "066EDFF7DF105E53", "9E5C3F34A7B7F808", "B9B83487A024A8ED", "25460AA385FD313A", "3EBE0E45809B5D19", "51DD5D5C7651B620", "0749CD23A6DD8B52", "480EBB59766D252C",
                "CC2793E55B943FFF", "1D1CDC2EA28314D3", "8A4541FFA7135EDB", "CCFE1F10356BB896", "956A40551304A36A", "17CC1F427F3E0AD3", "1F88C08EA66554AB", "51713EDDC2561071", "9E40BF4C5A9B050F", "9A1562C28DA19E87", "11DC6DF4B6F925D1", "F0DE5B1759105F0F", "F229358CFD28795E", "484E2B1C2ED802C7", "E1F5B221B9ACB8AD", "74B09B92646A94CB", "FB95FD7C52E252AC", "8FCAB87CF8FA8B2E", "FE6D8E536A8FB181", "69AEEB2B08C5BC87", "05D286BDC34BC79F", "9657A7BB85B7359B", "58B45B194E455AA7", "78947BF7D513EE8C", "4EBF2F44A79E04B5", "727EE4E1D7E70EFB", "35391F7D0D19284C", "C133EF4F2376A1D7", "26388554089A2E05", "A5197759DE2B9FD3",
                "EDA95B85FEC7878E", "CE596205B6C4B364", "1599F9BE0382DD10", "64A03BA124661A94", "A9EB48F6EC65609C", "E851B4D2771BACC3", "37F62EB152865EDC", "64E3F889C7449676", "131392DB7B74825C", "8D5B9600A8A68680", "F3239CD305D97D8B", "C172E92850570901", "0A8337362DA8B1E7", "2C4C4EA7B37991DE", "671B0B3E76B11A0C", "53B714F5771ECFCE", "7D71F92EF0901E17", "573ACBAE15B02042", "D5D852A340551887", "0C2790BD459F15EA", "E296B0DC5AF528CE", "6C0805ACE9AC4F2D", "9AE2AB699E121958", "0029B63A0AF9D7B7", "25D1CB9C8FD39AF9", "71ABFABF7302E50A", "0400E5D15A80679F", "FCCAC2C6D1FEFD7F", "A29965DAC2573339", "B5DFADD8B596B74E",
                "1833A67D57646226", "9D6D42870A7A5632", "889BA1B18059910B", "C23897EB14904672", "DD64FB280E1444CE", "423745E562FAEB4E", "3033FE7CA6B2BB55", "E931F3E900EDF69D", "63056CA0BD28F174", "61247AFBE25DA18E", "1B18152EF164D480", "4633BF8F0455EA92", "96D1F9EEE0F763E2", "44BD5882DD9D8609", "707514253D3D524B", "DA3D5FEF9FC878E8", "27FE31D308D0E861", "59924763B1E47890", "D52A3FDDDD5C46D8", "F1D487F3DB1CE204", "FC9EF9E16C71D980", "C812CBE12054C489", "D0F17D38039C76B6", "4DEE270B0DB9124A", "676A1411DB3770EC", "8EB4D3148234F64F", "6E507569D84FEC1A", "7866915780876DFC", "39561061E70A717D", "28B1844A6FCDEA4B",
                "5B730D8C4B6F05DE", "4C4E7A5D52FE611E", "4E6B222E010F5305", "9F1E4B6A8F6A57EF", "A8CAAF015154BE04", "2EBF32D84875AAFA", "810738BC03C01D25", "A4F0AC8A53FC2C71", "0DBE0CD045CB028A", "A5EF4E1C7ABE1534", "7337A8794D434BC7", "0396B8EFC14FBB44", "DCC486E0B7B41E28", "D91938A256883DEE", "BF3C0364D7154D6C", "510707867E6C66C4", "5EE216A86C50A774", "2E22D26FEAD58977", "05D7E6499F446D1A", "1D1CDC2EA28314D3", "EC38D8D4BFAF594F", "2740E375483CBEC1", "B437045BDD6A921D", "29644AF70C57770E", "7FDB23D95E3DBBC7", "061239AA98B4D6C0", "6F33C5AF7C201709", "335375FDAD7E978D", "F56EB057AAA60965", "1F487E25E210CB4A",
                "52B10B59197647CE", "F03B447BD8439393", "8877E43746FEC7D1", "B4BE7C94AC2CB6AD", "B8D43A6522F9D83D", "72F86A5A6F9FF337", "F91F78572B2CEF3D", "D3B639E03028FF60", "EFAA20FF96A344DD", "ECD8AF660423CA3D", "B5FEF639E35969FE", "6F8E1F245DAAFB5A", "FBF8E4AB928BCB43", "ED8E007795622222", "E0FDFBF128C9B6EF", "403769B9B96B0C56", "CB0A16DFF9658CF2", "31AB372FDAB8D770", "8DA1BB77B0DC6770", "AE3A260E3BF721B2", "23A9E406B1F95A68", "9AEF9C508F20DFBA", "0FFBDA6341781247", "949160B18D898DF6", "180F1364483754A4", "189AA9D608B4422B", "3E0BDF83D5133CBE", "7C7757E6E9B6FA48", "BF2F9945CAFBB40D", "005D8036B962C539",
                "39AFF0D9D2ECF03A", "8B3871DA282AA329", "834A4E9D91CD5662", "677456A23E100DE9", "A94FF9B330C0CC3C", "95F5C5C965E8CFFE", "AC27A39E09C3ED99", "51233331F145C64F", "C735A3608399C177", "E57F4F511C452E24", "4C05810767FCC717", "D3286538655E49C3", "32973D6C39CF4E4C", "2EACECE64033A069", "B0DDA16EE4F2FDD6", "7271667AC88EAB34", "D280514885DEBD48", "2D6224BE45715169", "8AABDD6EAD841FC4", "8A64D40444BC162A", "56FEDA2681151022", "8E7542667542978C", "B6D91C5E6E052035", "CB20976B58B865CB", "5F09D4E8F1CCCF6D", "B8D43A6522F9D83D", "64B34C692FA236F7", "CD60AE6CB888CD78", "6D31026E3B69235B", "9D3591569B038BE6",
                "EC08941379653191", "494F3AE4A2AD4FCC", "22ADC057D8AB0406", "9E1FBF0ED45E95C2", "8EB4D3148234F64F", "E369AB2D98CE429E", "3114BE0C9440BEA0", "F6ED51E83123A63E", "11068F695725EBB6", "47B7F2A962CA09A3", "B8105FAAB7419572", "F1A0CEE9D92BCB0A", "94659369C35E7E3F", "0E41919248C61775", "6A8669E60ED77109", "29CD81CEF2510672", "459FA6A4E8B5D293", "F0CF5A26228414D2", "DA178D5077D598D7", "FF70B32E6ECCC109", "F19DFD67A54C1ABD", "2FF92CE06B0E26A2", "95157CA1B0E9AE61", "0F7DD6F861D052EC", "9432BEF7206D68CA", "2A5B80A2674626AA", "90AF014D9D0D05C7", "7ACE9C9275EBC5CC", "7E23D41BBB3FD26A", "676623723024913E",
                "E51A8181B6696E1A", "6F7335AD73E15944", "2AF2F2D9471A8067", "312F31535DC17232", "6AD721AFD10EED9E", "175D138B136A9690", "11F67BEB1411B91C", "D74843A810001275", "DA94F5727E5D6882", "ECB0A30F1A518809", "21674C9748E3C2E6", "C60C5FE75F6059AB", "F0ED25D61ACBC153", "3A9CD2B39043420E", "0E53C67997273B93", "75B5C1B4108732FE", "CE4489802DE48545", "6C1E4583D8658791", "A2E7AC890569467E", "5483204365420886", "400FDB98E002D884", "1C806FB55AE5E82E", "AE6DD7E2418FB53B", "9762D66AF799EFA4", "D53A256A2F6F915E", "7BBBBE4FEB71326D", "B3A854172BD69CBE", "899A1D2017C4EF4B", "AE95984C11DADCD6", "0D68FA4368C64C98",
                "A476B9EE64905373", "DF3E1D15DE844FC4", "45A16D76B2C62D66", "DC46EDA78CD86175", "68304DC3906E55A0", "61CB97210663CB7E", "0E47BF3418745336", "1A6F5F027D70C329", "78FE3604B1A05FEC", "16A7E7871BE7E424", "BC838B66B490909D", "0DD591BE027E8667", "3566DA4C6E480FD6", "0FFB733B15616AEA", "A9B8667184CFA060", "123E603CE759969C", "07F2C84273FCB57A", "4352E4815D76E98C", "A619E04CCC470BD0", "1D7AFAA056EDE067", "46989C959AB0D8F4", "1B5435AEC93CBCEA", "7F183EFD0F40A1AC", "C077B396680F98B0", "673EFAF8AFEA6EAA", "6E2637309E350E6D", "01FB4838615BA454", "6AB2605DE4236768", "30AD8012600836E5", "DEC69BCF8766BC19",
                "2BA5B152D5AE850F", "B5402056A8D34889", "06A1B5DA42CF4A64", "1E5CBB6002875176", "5C42A3CABE1B5791", "FCD40778C781E575", "B03214C497C5AAB6", "24F04EEF4511D2CD", "7D6C61E8FFB96DC7", "6CE63BB3229EF976", "B9034CAB08A7BEA3", "9C6A9688E7C7D021", "523A27D6C94F7245", "6C815B611635CFBC", "BDCD7DCA2ACD89A6", "35149F5747176C6F", "B40380366AB25FD1", "AA7A2ED976C188B8", "8456A0F0690D7EBA", "C6BEB725B28A7197", "E23D814D2908492E", "7B3C72B6B03D1634", "F6466B3328D6E8F6", "7F43E8BDF64E43DD", "DB7E5C9E9A7BEF86", "43F4290A65FB6DBF", "D9BEEBC75C797B8C", "1E292360CB0A9306", "9B4CE848EDCB0F8E", "7D37B72B9398E105",
                "E35CF28CFF04FA16", "30EE41E7FD2E305D", "1B04B3EB9791093F", "6EB17564CF53A249", "AEC6F194EEFF23EA", "45B7550F2E3BA052", "0AB38E2D518EACD3", "F923C4D271F68AE2", "7F2038CA843F5E2B", "5E9925BE587B077C", "03F1F55A9526B440", "4461CDD20AC9A233", "5B0E5CF0E092B1CC", "62FBFD752C9C5995", "A34B89649F13924A", "A2BF4D4A490FF94E", "6F44681A43C4A69C", "67E1344049FAD374", "8EB9262B5FF174C8", "094750FECFFBC6E6", "C040619DD1F1C5ED", "D04FB35838C0157D", "873BD2275EC5357E", "EC9C15589FDD8B19", "EC1F5A653AF16D11", "D834FC6F039CDA7A", "75C2AC36CE1E5752", "69F93098F6F64275", "74715927B798E019", "9EA6086768A9C86A",
                "216AC72B389968E1", "D3C69FEA5F29C96D", "156021519AEB51BA", "A00D1D2DDEEB57FC", "09DB99746636E84B", "F234755BB08AF0FE", "7D48566AC1740E60", "7BF7EA60FA52DF79", "B48DFB16977F3018", "C53E02CD89BC3F9B", "1091A487A85AD007", "DE756C478DD0579F", "D3AE9657A1D11E25", "1FFF3EDCDC023259", "648D64AA2C8B6561", "3CFAF0A20597575B", "941C1223D0103A99", "38AE9BA338EFB1E5", "AD7B9F05F8D5F030", "97AAA9E077861048", "774FEBD4D700DF1E", "E00C0E10DAACE19F", "6FE61F31E3434DA9", "714B7F723E46FBF9", "1455A6B491736267", "7BFEF144774ACE5D", "68209EE3BC09AE78", "CC33F5CFBA4F6DE5", "18BE2F8761E33A76", "5DACAABD1EE76EB1",
                "053808A84D6168C3", "12393B9889C97FE4", "DC20A7BE47241992", "3E17DE6D48F6257F", "3E04543C9A65AA9C", "15B4ADECC1A4C5C0", "F61C79A2E5C25037", "A8517300DEB3A531", "15419FE4DBE54BF1", "3E048AF936595CE8", "362CF57B98AEEC56", "047047D93DD424FD", "8C5DE7EEA166B0E2", "F4B803A65182C0C0", "FF88E11F76F9A248", "8B53F4A2C5BBC0F6", "B922CF0F67D1F2C7", "DEA6DFFE29380026", "5CA3EC33B513E168", "92130D8BFB774E56"};
        //@NoUseNewKeyEx return 1;//如果没有使用这个功能，直接返回1


        for (n = 0; n < 255; n++) {
            DevicePath = j9.FindPort(n);
            if (j9.get_LastError() != 0) return (int) j9.get_LastError();
            outString = j9.EncString(EncInString[myrnd], DevicePath);
            if ((j9.get_LastError() == 0) && (outString.compareTo(EncOutString[myrnd]) == 0)) return 0;
        }
        return -92;
    }

    private String myhex(byte indata) {
        String outString;
        outString = String.format("%X", indata);
        if (outString.length() < 2) outString = "0" + outString;
        return outString;
    }

    //若某字节为负数则需将其转成无符号正数
    private long conver(byte temp) {
        long tempInt = (int) temp;
        if (tempInt < 0) {
            tempInt += 256;
        }
        return tempInt;
    }

    //以下用于将16进制字符串转化为无符号长整型
    private int HexToInt(String s) {
        String[] hexch = {"0", "1", "2", "3", "4", "5", "6", "7",
                "8", "9", "A", "B", "C", "D", "E", "F"};
        int i, j;
        int r, n, k;
        String ch;

        k = 1;
        r = 0;
        for (i = s.length(); i > 0; i--) {
            ch = s.substring(i - 1, i - 1 + 1);
            n = 0;
            for (j = 0; j < 16; j++) {
                if (ch.compareToIgnoreCase(hexch[j]) == 0) {
                    n = j;
                }
            }
            r += (n * k);
            k *= 16;
        }
        return r;
    }


}
